package com.imooc.utils;

import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 顾志杰
 * @date 2020/9/3-15:10
 */
@Service
public class FastsfsUtil {
    @Autowired
    private FastFileStorageClient fastFileStorageClient;

    public String upload(MultipartFile file) throws Exception {
        /*文件名*/
        String upFileName = file.getOriginalFilename();
        /*文件后缀名*/
        assert upFileName != null;
        String fileExtName = upFileName.substring(upFileName.lastIndexOf(".")+1);

        StorePath storePath = fastFileStorageClient.uploadFile(
                /*文件流*/
                file.getInputStream(),
                /*文件大小*/
                file.getSize(),
                fileExtName,
                null);
        String pash = storePath.getFullPath();
        return pash;
    }
}
